package com.yzh.grainmall.product.web;

import com.yzh.grainmall.product.entity.CategoryEntity;
import com.yzh.grainmall.product.service.CategoryService;
import com.yzh.grainmall.product.vo.Catelog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author yuzhen
 * @create 2021-06-19 17:33
 */
@Controller
public class IndexController {

    @Resource
    private CategoryService categoryService;

    @GetMapping({"/", "/index.html"})
    public String  indexPage(Map<String, List<CategoryEntity>> map) {
        List<CategoryEntity> entities = categoryService.getLevel1Catergorys();
        map.put("categorys", entities);
        return "index";
    }

    //index/catalog.json
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatelogJson() {
        Map<String, List<Catelog2Vo>> map = categoryService.getCatalogJson();
        return map;
    }

}
